//************************reporting module scripts***************************

//cost manage re-bill

function validateRebillPercentage()
{
	var rebillValue = document.getElementById("rebillEqualPercentage").value
	//alert("rebill value = "+rebillValue)
	if(rebillValue > 100){
		alert(invalidPercentageNumber)
		return false;
	}else {
		return true;
	}
} 

//findCall

function show(arg)
{
	divn = document.getElementById(arg)
	divn.style.display = "block";
}

function hide(arg)
{
	divn = document.getElementById(arg)
	divn.style.display = "none";
}

function doStuff(obj2,txt)

{
    if (txt == '')
	{
		document.getElementById(obj2).innerHTML='';
	}
	else
	{
		document.getElementById(obj2).innerHTML='<table border="1" align="left" bordercolor="#0000FF"><tr><td><font color="#0000FF">' + txt + '</font></td></tr></table>';
	}
}


function checkOption(opt)
{
	list = document.getElementById(opt)

	if (list.value == 'Between')     // Between
	{
        show(opt+'div1')
        hide(opt+'div2')
        hide(opt+'div3')
        hide(opt+'div4')
	}

	if (list.value == 'Greater Than')   // Greater Than
	{
        show(opt+'div2')
        hide(opt+'div1')
        hide(opt+'div3')
        hide(opt+'div4')
	}

	if (list.value == 'Less Than')     // Less Than
	{
        show(opt+'div3')
        hide(opt+'div1')
        hide(opt+'div2')
        hide(opt+'div4')
	}
    if (list.value == 'Equal To')     // Equal
	{
        show(opt+'div4')
        hide(opt+'div1')
        hide(opt+'div2')
        hide(opt+'div3')
	}
    if (list.value == '')             // nothing
	{
        show(opt+'div4')
        hide(opt+'div1')
        hide(opt+'div2')
        hide(opt+'div3')
	}
//alert(list.value);
}


/* start() makes all DIV div1 appear*/

function start()
{
    checkOption('totSelect');
    checkOption('TollChargesSelection');
}

function resetForm()
{
    document.FindCallForm.reset();
    checkOption('totSelect');
    checkOption('TollChargesSelection');
}

//-- !>


//promptReportPopUp

function sendDataToParent(action){
	if(action == 'CLOSE'){		
		var batchReportPage = false;
		try{		
			if(window.opener.document.forms[0].id=="batchReportScheduleRequestForm"){
				batchReportPage=true;
			}
		}catch(e) {					
		}
		if(!batchReportPage) {
			window.opener.document.getElementById(document.forms['promptReportForm'].promptName.value).selectedIndex=0;
			if(document.forms['promptReportForm'].promptSubmit.value == "true"){
				 window.opener.document.forms[document.forms['promptReportForm'].promptFormName.value].submit();
			}
			document.forms['unloadCheck'].windowClose.value = "0";
			window.close();
		} else {
			document.forms['unloadCheck'].windowClose.value = "0";
			window.close();
		}		
		return true;
	}		
	if(action == 'SUBMIT'){
		if(document.forms['tran1_pagingForm1']){
		if(document.forms['tran1_pagingForm1'].cell_radio_0.value == ""){
			alert(document.forms['promptReportForm'].unSelectedMessage.value);
		}else{
			document.forms['promptReportForm'].action.value = action;
			document.forms['promptReportForm'].reportId.value = document.forms['tran1_pagingForm1'].reportId.value;
			document.forms['promptReportForm'].cell_radio_0.value = document.forms['tran1_pagingForm1'].cell_radio_0.value;
			document.forms['unloadCheck'].windowClose.value = "0";
			document.forms['promptReportForm'].submit();
			return true;
		}
		return false;
	}else{
		if(document.forms['formWithoutPaging'].cell_radio_0.value == ""){
			alert(document.forms['promptReportForm'].unSelectedMessage.value);
		}else{
			document.forms['promptReportForm'].action.value = action;
			document.forms['promptReportForm'].reportId.value = document.forms['formWithoutPaging'].reportId.value;
			document.forms['promptReportForm'].cell_radio_0.value = document.forms['formWithoutPaging'].cell_radio_0.value;
			document.forms['unloadCheck'].windowClose.value = "0";
			document.forms['promptReportForm'].submit();
			return true;
		}
		return false;
	}
	}	
}
	
function windowClose(){
	if(document.forms['unloadCheck'].windowClose.value=="1"){
		if(document.forms['tran1_pagingForm2'].pagingAction.value=="submit" && document.forms['tran1_pagingForm1'].pagingAction.value=="submit"){
		   window.opener.document.getElementById(document.forms['promptReportForm'].promptName.value).selectedIndex = 0;
		   if(document.forms['promptReportForm'].promptSubmit.value == "true" && document.forms['sendDataForm'].sendData.value != "1"){
		      window.opener.document.getElementById(document.forms['promptReportForm'].promptName.value).onchange();
   		   }			   
		}
	}
}


//ServiceTransactionDetail

function gotoDispute(url)
{
	var x="600";
	var y="550";
	try{
		url = url+"?serviceDetailKey="+document.forms['splitBillingForm'].serviceDetailKey.value+"&serviceDetailFactTableId="+document.forms['splitBillingForm'].serviceDetailFactTableId.value+"&parentReportId="+document.forms['splitBillingForm'].parentReportId.value+"&id="+document.forms['splitBillingForm'].id.value;
		window.location.href=url;
	}catch(e){
		alert(' Unable to open up the page '+url);
	}
}
	
	
function fnPrintPopup(url)
{
	url = url+"&serviceDetailKey="+document.forms['splitBillingForm'].serviceDetailKey.value;
	window.open(url,'Print_Friendly','width=700,height=650,scrollbars=yes');
}
	
function fnDownloadPopup(url)
{
	url = url+"&serviceDetailKey="+document.forms['splitBillingForm'].serviceDetailKey.value+"&reportId=serviceTransactionDetail&type=csv&templateId=CSV_TEMPLATE"
	window.location.href=url;
}
	
// Added to refresh the parent window.
function refreshParent() 
{
	window.opener.reloadReport(window.opener.location.href);
	if (window.opener.progressWindow)
	{
		window.opener.progressWindow.close();
	}
	window.close();
}

function refreshParent(reportId) 
{
	if (window.opener.location.href.indexOf(reportId)!=-1) {
		window.opener.reloadReport(window.opener.location.href);
	}
	else {
	    //Check if the url already contains ?, if yes, append "&reportId"
		if(window.opener.location.href.indexOf("?", 0) < 0){
		    window.opener.reloadReport(window.opener.location.href + "?reportId=" + reportId);
		}else{
		    window.opener.reloadReport(window.opener.location.href + "&reportId=" + reportId);
		}
	}
	if (window.opener.progressWindow)
	{
		window.opener.progressWindow.close();
	}
	window.close();
}

function setCellInput( element1,  element2, status){
    element1.value=status;
    element2.value=status;
}

